package com.futures.questionbank.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.futures.questionbank.R;
import com.futures.questionbank.db.table.exam;
import com.futures.questionbank.db.table.problem;
import com.futures.questionbank.db.table.problem_Table;
import com.github.lzyzsd.circleprogress.DonutProgress;
import com.raizlabs.android.dbflow.sql.language.SQLite;

import java.text.DecimalFormat;
import java.util.List;

public class ExamAdpter extends BaseRecycleAdapter<exam> {
    private List<exam> dataList;
    private Context mContext;
    private BaseViewHolder.onItemCommonClickListener commonClickListener;



    public ExamAdpter(Context context, List<exam> dataList, BaseViewHolder.onItemCommonClickListener commonClickListener) {
        super(context, dataList, R.layout.itme_chapter_list4);
        this.dataList = dataList;
        this.commonClickListener = commonClickListener;
        mContext = context;
    }

    @Override
    public void bindData(BaseViewHolder holder, exam data) {
        holder.setText(R.id.tv_management, data.getTitle()).setCommonClickListener(commonClickListener);

        DonutProgress process = (DonutProgress)holder.getView(R.id.donut_progress);

        List<problem> problems = SQLite.select().from(problem.class).where(problem_Table.exam_id.eq(data.getId())).queryList();
        int i = 0;
        for (problem problem : problems) {
            if(!TextUtils.isEmpty(problem.getMy_answer())){
                i++;
            }
        }
        DecimalFormat df = new DecimalFormat("#.00");
        String a = df.format((float)i/problems.size());
        process.setProgress(Float.valueOf(a)*100);
    }
}
